package com.sos.core.cards 
{
	import com.sos.utils.ClassUtils;
	
	public class CardTargetInputRoleType
	{
		
		// -------------------------------------------------------------------------------
		// CONSTANTS
		// -------------------------------------------------------------------------------		
		
		public static const NONE:CardTargetInputRoleType				= new CardTargetInputRoleType(0, "none",	"None");
		public static const GOALKEEPER:CardTargetInputRoleType			= new CardTargetInputRoleType(1, "gk", 		"Goalkeeper");
		public static const DEFENSE:CardTargetInputRoleType				= new CardTargetInputRoleType(2, "df", 		"Defence");
		public static const MIDFIELD:CardTargetInputRoleType			= new CardTargetInputRoleType(3, "mf", 		"Midfield");
		public static const FORWARD:CardTargetInputRoleType				= new CardTargetInputRoleType(4, "fw", 		"Forward");
		public static const REACH:CardTargetInputRoleType				= new CardTargetInputRoleType(5, "reach",	"Reach");
		public static const ANY:CardTargetInputRoleType					= new CardTargetInputRoleType(6, "any",		"Any");
		
		// -------------------------------------------------------------------------------
		// STATIC
		// -------------------------------------------------------------------------------
		
		private static var _initialized:Boolean = false;
		private static var _list:Vector.<CardTargetInputRoleType>;
		
		// Fake static constructor
		{
			// Fill the internal list
			_list = new Vector.<CardTargetInputRoleType>();
			_list.push(CardTargetInputRoleType.NONE);
			_list.push(CardTargetInputRoleType.GOALKEEPER);
			_list.push(CardTargetInputRoleType.DEFENSE);
			_list.push(CardTargetInputRoleType.MIDFIELD);
			_list.push(CardTargetInputRoleType.FORWARD);
			_list.push(CardTargetInputRoleType.REACH);
			_list.push(CardTargetInputRoleType.ANY);
			// Init!
			_initialized = true;
		}
		
		// -------------------------------------------------------------------------------
		// FIELDS
		// -------------------------------------------------------------------------------
		
		private var _id:uint;
		private var _name:String;
		private var _sign:String;
		
		// -------------------------------------------------------------------------------
		// CONSTRUCTORS
		// -------------------------------------------------------------------------------
		
		public function CardTargetInputRoleType(id:uint, sign:String, name:String)
		{
			// Safe unique instance lock
			if (_initialized) throw new Error("PlayerCardTargetInputRoleType enum already created!");
			// Init
			_id    = id;
			_name  = name;
			_sign  = sign;
		}
		
		// -------------------------------------------------------------------------------
		// PROPERTIES
		// -------------------------------------------------------------------------------		
		
		public function get id():uint
		{
			return _id;
		}
		
		public function get sign():String
		{
			return _sign;
		}
		
		public function get name():String
		{
			return _name;
		}
		
		// -------------------------------------------------------------------------------
		// PUBLIC METHODS
		// -------------------------------------------------------------------------------
		
		public function toString():String
		{
			return ClassUtils.getName(this) + "." + _name;
		}
		
		// -------------------------------------------------------------------------------
		// STATIC METHODS
		// -------------------------------------------------------------------------------
		
		/**
		 * Returns the list of the names of 
		 * @return 
		 */
		public static function names():Array
		{
			var list:Array  = new Array;
			// Loop over values list
			for (var i:int=0; i<_list.length; i++)
			{
				list.push(_list[i].name);
			}
			return list;
		}
		
		/**
		 * 
		 * @return 
		 */
		public static function list():Array
		{
			var list:Array = new Array;
			// Loop over values list
			for (var i:int=0; i<_list.length; i++)
			{
				list.push(_list[i]);
			}
			return list;
		}
		
		/**
		 * Search a CardTargetInputRoleType by given id 
		 * @param id Id of the card type to find
		 * @return PlayerCardTargetInputRoleType constant for the given id, null if no CardTargetInputRoleType
		 * for the given id has been found
		 */		
		public static function getById(id:uint):CardTargetInputRoleType
		{
			// Search the value into the list
			for (var i:int=0; i<_list.length; i++)
			{
				if (_list[i].id == id) return _list[i];
			}
			throw new Error("CardTargetInputRoleType for id '" + id + "' unknown!");
		}
		
		/**
		 * Search a CardTargetInputRoleType by given name 
		 * @param name Name of the player CardTargetInputRoleType to find
		 * @return PlayerCardTargetInputRoleType constant for the given id, null if no CardTargetInputRoleType
		 * for the given name has been found
		 */		
		public static function getByName(name:String):CardTargetInputRoleType
		{
			// Search the value into the list
			for (var i:int=0; i<_list.length; i++)
			{
				if (_list[i].name == name) return _list[i];
			}
			throw new Error("CardTargetInputRoleType for name '" + name + "' unknown!");
		}
		
		/**
		 * Search a CardTargetInputRoleType by given sign 
		 * @param name sign of the player CardTargetInputRoleType to find
		 * @return PlayerCardTargetInputRoleType constant for the given id, null if no CardTargetInputRoleType
		 * for the given sign has been found
		 */		
		public static function getBySign(sign:String):CardTargetInputRoleType
		{
			// Search the value into the list
			for (var i:int=0; i<_list.length; i++)
			{
				if (_list[i].sign == sign) return _list[i];
			}
			throw new Error("CardTargetInputRoleType for sign '" + sign + "' unknown!");
		}
		
	}
}